package com.example.sonny.dutest;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

import com.example.sonny.dutest.interfaces.BaseActivityI;

public class MainActivity extends BaseActivity implements  BaseActivityI{

	Button btnSignIn;
	Button btnSignUp;


	private SharedPreferences sp;

	private String mode;

	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //setContentView(R.layout.flatui_sample);

        checkState();//if already signed in
        preInit();
        initView();
        initListener();
        initData();
    }

    private void checkState() {
        sp = getSharedPreferences("sign",0);
        mode = sp.getString("email","");
        if(!mode.equalsIgnoreCase("")){
            startNewActivity(MenuActivity.class);
            finish();
        }
    }

    @Override
	public void onClick(View v) {
		Intent i = null;
		switch(v.getId()){
			case R.id.btnSingIn:
				i = new Intent(this,SignInActivity.class);
				break;
			case R.id.btnSignUp:
				i = new Intent(this,SignUpActivity.class);
				break;
		}
		startActivity(i);
	}


    @Override
    public void preInit() {

    }

    @Override
    public void initView() {

        btnSignIn = (Button) findViewById(R.id.btnSingIn);
        btnSignUp = (Button) findViewById(R.id.btnSignUp);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {

        btnSignIn.setOnClickListener(this);
        btnSignUp.setOnClickListener(this);
    }
    protected void startNewActivity(Class target){
        Intent intent = new Intent();
        intent.setClass(getApplicationContext(), target);
        startActivity(intent);
    }
}
